﻿namespace TomatoBreak.DataAccess.Mapping
{
    using NHibernate.Mapping.ByCode;

    using DomainObjects;

    public class TaskMap : IClassMap
    {
        public void Map(ModelMapper mapper)
        {
            mapper.Class<Task>(m =>
            {
                m.Id(t => t.Id);

                m.Property(t => t.Name, c =>
                {
                    c.NotNullable(true);
                    c.Length(256);
                });

                m.Property(t => t.Planned);

                m.Property(
                    t => t.Notes, c =>
                {
                    c.NotNullable(false);
                    c.Length(4001);
                });

                m.Property(t => t.Estimation);

                m.Property(
                    t => t.CreatedAt,
                    c => c.Index("IX_Task_UserId_CreatedAt"));

                m.Property(
                    t => t.DueAt,
                    c => c.Index("IX_Task_CompletedAt_DueAt_Archived"));

                m.Property(
                    t => t.CompletedAt,
                    c => c.Index("IX_Task_CompletedAt_DueAt_Archived"));

                m.Property(
                    t => t.Archived,
                    c => c.Index("IX_Task_CompletedAt_DueAt_Archived"));

                m.ManyToOne(
                    t => t.User, c =>
                {
                     c.Column("UserId");
                     c.NotNullable(true);
                     c.ForeignKey("FK_Task_User");
                     c.Index("IX_Task_UserId_CreatedAt");
                });
            });
        }
    }
}